<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Test extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */

	public function index()
	{
//echo	    number_format("13459", 0, '', ',');
  // echo  implode(",", str_split("5600", 3));
       /* $this->db->update('products', array(
            'image1' => "http://tuna.icmproje.com/public/uploads/urun_1.jpg",
            'image2' => "http://tuna.icmproje.com/public/uploads/urun_1.jpg",
            'image3' =>  "http://tuna.icmproje.com/public/uploads/urun_2.jpg",
            'image4'   => "http://tuna.icmproje.com/public/uploads/urun_3.jpg",
            'image5'    => "http://tuna.icmproje.com/public/uploads/urun_4.jpg"
        ));*/
        	
        $this->load->helper('assets');
        $this->load->library('Assets');
        
        // Js
   /*     $this->assets->add('jquery.js');
        $this->assets->add('bootstrap.js');
        $this->assets->add('jquery.fancybox.js');
  //      $this->assets->add('jquery.flexslider.js'); // gidicek
      
      
        $this->assets->add('jquery.carouFredSel-6.1.0-packed.js');
        $this->assets->add('custom.js');
        $this->assets->add('cloud-zoom.1.0.2.js'); */
        $this->assets->add('jquery.easing.1.3.min.js');
        $this->assets->add('jquery.wt-rotator.js');
        $this->assets->add('jquery.wt-rotator.min.js');
        $this->assets->add('jquery-1.7.1.min.js'); 
        // Css
    /*    $this->assets->add('bootstrap.css');
        $this->assets->add('bootstrap-responsive.css');
        $this->assets->add('style.css');*/
   //     $this->assets->add('flexslider.css'); // gidicek
        $this->assets->add('wt-rotator.css');
   //     $this->assets->add('jquery.fancybox.css');
      //  $this->assets->add('cloud-zoom.css');
        
        $this->load->view('test2');
        
	}
    public function xtest()
    {
      /*  for($i = 0; $i < 500; $i++)
        {
            $this->db->insert('products',array('category_id'=>'1', 'subcategory_id' => '1' , 'brand_id' => '1', 'name' => 'test') );
        }
*/

echo "<pre>";
print_r($this->session->userdata);
        
    
    }
    public function search($value)
    {
      //  $start_rowa
        $per_page = 5;
        $start_row = $this->uri->segment(4);
        if(trim($start_row)== "")
        {
            $start_row = 0;
        }
     // AND category_id = ?
     
     
        $sql = "SELECT * FROM products , seller WHERE  seller.product_id = products.product_id  AND 
      (products.name LIKE ? OR products.model LIKE ? ) 
      group by products.product_id  LIMIT $start_row, $per_page";
      $result =  $this->db->query($sql,array('%'.$value.'%','%'.$value.'%'));
        
        
        // AND category_id = ?
        
            $sql2 = "SELECT * FROM products , seller WHERE  seller.product_id = products.product_id  AND 
      (products.name LIKE ? OR products.model LIKE ? ) ";
            $result2 =  $this->db->query($sql2,array('%'.$value.'%','%'.$value.'%')); 
            
            
        $config['base_url'] = base_url()."test/search/".$value;
        $config['total_rows'] =  $result2->num_rows(); //$this->db->where(array('brand_id' => $brand_id , 'category_id' => $category_id , 'subcategory_id' => $subcategory_id ))->get('products')->num_rows();
		$config['per_page'] = $per_page;
     //   $config['uri_segment'] = '4';
  
        
        
        //$config['page_query_string'] = TRUE;
      //  $config['use_page_numbers'] = TRUE;
        $config['next_link'] = 'Sonraki';
        $config['next_tag_open'] = '<li>';
        $config['next_tag_close'] = '</li>';
        $config['prev_link'] = 'Önceki';
        $config['prev_tag_open'] = '<li>';
        $config['prev_tag_close'] = '</li>';        
        
        $config['cur_tag_open'] = '<li class="active"><a href="#">';
        $config['cur_tag_close'] = '</a></li>';
        

        
		$config['full_tag_open'] = ' <div class="pagination pull-right"><ul>';
		$config['full_tag_close'] = '</ul></div>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';
	
		$this->pagination->initialize($config);
        
        
                $data['pagination'] = $this->pagination->create_links();
                $data['products'] = $result->result();
                $data['total'] = $result2->num_rows();
                $data['subview'] = 'urunler/view_urunler_arama_new';
                $this->load->view('layouts/default3',$data);  
    }
    public function update_db()
    {
        $result = $this->db->get('products')->result();
        {
            foreach($result as $row)
            {
                if($row->image1 == "" or $row->image1 == NULL)
                {
                    $this->db->where('product_id',$row->product_id)->update('products',array('image1' => 'http://tuna.icmproje.com/public/uploads/noimage.png'));
                }
            }
        }
        
        
    }
    public function try1()
    {
        try
        {
          $result = $this->db->insert("users",array("2353254"=>'sdfasd'));
          if(!$result)
          {
            throw new Exception("Error message: ".$this->db->_error_message()."<br>"."Error number: ".$this->db->_error_number());
          }  
            
        }
        catch(Exception $e)
        {
            //$heading, $message, $template = 'error_general', $status_code = 500
           // show_error('heading bu',$e->getMessage(),'error_general');
            log_message('error', $e->getMessage()); 
            log_message('info', 'The purpose of some variable is to provide some value.');
             log_message('qqq', 'The psdgfdsfgis to provide some value.');
            show_error($e->getMessage());
            
        }
        echo "hello ww";
    }
    function try2()
    {
       $this->load->view('test'); 
    }
        function curltest()
    {
        //phpinfo();
        //var_dump( $this->curl->simple_get('http://example.com/'));
       $test = array(
        'USER' => "tunailgaz-facilitator_api1.gmail.com",
        'PWD' => "1364803509",
        'SIGNATURE' => "AmL1bOjuDVJoyZHSzEOQHxchMcmWAXhYisnBXYprKYTTGOn", //TODO
        'RETURNURL' => "http://localhost/AuthApiex/AuthReturnURL.php", //TODO
  	    'CANCELURL' => "http://myCancelURL", //TODO
  	    'LOGOUTURL' => "http://myLogoutURL", //TODO
        'VERSION' => "3.300000",
        'METHOD' => "SetAuthFlowParam"
										);
        var_dump($this->curl->simple_post('https://api.sandbox.paypal.com/v1/oauth2/token',$test));
        echo "<pre>";
        var_dump($this->curl->execute);
        echo "<hr><br>";
       
    }
    function garanti()
    {
        $this->load->view('garanti');
    }
    function garanti_error()
    {
        echo "<pre>";
        var_dump($this->input->post());
        
    }
    function qqqq()
    {
        echo "lol";
  /*       
    $opts = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"Accept-language: en\r\n" .
              "Cookie: foo=bar\r\n"
  )
);

$context = stream_context_create($opts);

// Open the file using the HTTP headers set above
$file = file_get_contents('http://asci.icmproje.com/index.php/api/example/tuna', false, $context);
    

  var_dump(file_get_contents('http://asci.icmproje.com/index.php/api/example/tuna')  );
//echo $user->name;d
*/
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => 'http://asci.icmproje.com/index.php/api/example/tuna',
    CURLOPT_USERAGENT => 'Codular Sample cURL Request'
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);
var_dump($resp);

    //    var_dump($this->load->library('REST', array('server' => 'http://asci.icmproje.com/index.php/api/example/')));
    $this->load->library('Curl'); 
    $this->load->library('Rest');
         $this->rest->initialize(array('server' => 'http://asci.icmproje.com/index.php/api/example/'));  
        echo "dasfads";

        
        // Pull in an array of tweets
        echo "<pre>";
        echo ($this->rest->get('users'));
        echo "qq";
    }
    
    
  
         
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */